﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Corsat.Library.DataManager
{
    public static partial class Main
    {
        public static DataTable GetExamAttendeesCount(DateTime examDate, int courseId)
        {
            try
            {
                //SqlParameter paramCourseId = new SqlParameter("CourseId", courseId);
                //SqlParameter paramExamDate = new SqlParameter("ExamDate", examDate);
                ////SqlParameter paramYear = new SqlParameter("Year", DateTime.Now.Year);
                //SqlParameter paramYear = new SqlParameter("Year", 2012);
                //dtMaster = GetData(StoredProcedure.sp_GetTechnologyExamAttendeesCount, new SqlParameter[] { paramCourseId, paramExamDate, paramYear }).Tables[0];

                command.CommandText = @"
SELECT  TechnologyCourseExamLab ExamLab ,
        TechnologyCourseExamPeriod ExamPeriod ,
        COUNT(*) AttendeesCount
FROM    AccountsDetails
WHERE   TechnologyCourseId = " + courseId + @"
        AND TechnologyCourseTestDate = '" + examDate.Date.ToString() + @"'
        AND year = " + DateTime.Now.Year + @"
GROUP BY TechnologyCourseExamLab ,
        TechnologyCourseExamPeriod
";
                command.CommandType = CommandType.Text;
                dtMaster = new DataTable();
                adapter.Fill(dtMaster);

                return dtMaster;
            }
            catch (Exception exc)
            {
                return null;
            }

        }

        public static void ReserveTechnologyCourse(TechnologyCourseReservation TechCourse)
        {
            try
            {

                command.CommandText = @"

UPDATE  dbo.AccountsDetails
        SET     TechnologyCourseId = " + TechCourse.Course.Id + @" ,
                TechnologyCourseExamLab = '" + TechCourse.Lab + @"' ,
                TechnologyCourseExamPeriod = " + TechCourse.Period + @" ,
                TechnologyCourseTestDate = '" + TechCourse.ExamDate.Date.ToString("MM-dd-yyyy") + @"' ,
                TechnologyCourseExamReservationDate = GETDATE()
        WHERE   AccountId = " + TechCourse.Account.Id + @"
                AND Year = YEAR(GETDATE())
                                      
                                        ";

                command.CommandType = CommandType.Text;

                OpenConnection();
                command.ExecuteNonQuery();
                CloseConnection();

            }
            catch (Exception exc)
            {

            }

        }
    }
}
